﻿#pragma once

#include <vector>

#include "common.h"

#include "game_object.h"


// 游戏对象基类
class GameObject
{
public:
    float realX, realY;
    float nextX, nextY;
    float velocityY = 0, velocityX = 0;
    int width, height;

    bool isMovable = false;

    bool isJumping = false;

    GameObject(int x, int y, int width, int height, bool isMovable);

    virtual void render(SDL_Renderer* renderer) = 0;

    virtual void beforeHandleCollision(const std::vector<GameObject*>& platforms);
    virtual void moveAndHandleCollision(const std::vector<GameObject*>& platforms);
    virtual void afterHandleCollision(const std::vector<GameObject*>& platforms);

    virtual void handleInput(const bool* keystates);
    virtual void beforeUpdate(const bool* keystates, const std::vector<GameObject*>& platforms);
    virtual void update(const bool* keystates, const std::vector<GameObject*>& platforms);
    virtual void afterUpdate(const bool* keystates, const std::vector<GameObject*>& platforms);

    virtual void jump();

    SDL_FRect getRealRect() const;
    SDL_FRect getNextRect() const;
};